﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BEPUphysics.Entities;
using Networking;
using Networking.Packets;

namespace MagicArenaXNA.ControllerInput
{
    class RemoteEntityController
    {
        public Entity Entity { get; private set; }
        public SimpleGameClient Client { get; private set; }
        public UInt64 PlayerId {get;private set;}

        public RemoteEntityController(SimpleGameClient client, Entity entity, UInt64 playerId)
        {
            Client = client;
            Entity = entity;
            PlayerId = playerId;
        }

        public void Update(float dt)
        {
            var pack = Client.LocationPackets.Find(LocationMatch);
            if (pack != null)
            { // If there is a packet for this entities location
                Entity.Position = pack.Location;
                Entity.Orientation = pack.Orientation;
            }
        }

        bool LocationMatch(LocationPacket other)
        {
            return other!=null && other.PlayerID==PlayerId;
        }
    }
}
